/**
 * @file   LoanAprvService.java
 * @date   2012-11-15下午3:06:53
 * @author User
 */
package com.gzceb.zhgjj.service;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.gzceb.zhgjj.util.SpringContextUtil;
import com.gzceb.zhgjj.web.dao.LoanAprvDAO;
import com.gzceb.zhgjj.web.entity.LoanAprv;

/**
 * <p>贷款审批服务层类。</p>
 *
 * @date   2012-11-15下午3:06:53 
 * @author liqing
 * @description 
 */
public class LoanAprvService {
	
	
	private LoanAprvDAO loanAprvDAO;
	
	public LoanAprvService(){
		
	}
	
	public LoanAprvDAO getLoanAprvDAO(){
		return this.loanAprvDAO;
	}
	
	public void setLoanAprvDAO(LoanAprvDAO loanAprvDAO){
		this.loanAprvDAO = loanAprvDAO;
	}
	
	
	/**
	 * 获取审批状态
	 * @param contCode 中心识别码
	 * @return 贷款审批状态 String
	 */
	public String getLoanStat(String contCode){
		
		LoanAprv loanAprv = new LoanAprv();
		loanAprv = loanAprvDAO.findByContcode(contCode);
		if( null != loanAprv ){
			return loanAprv.getLoanstat();
		}else{
			return null;
		}
		
	}
	
	/**
	 * 判断是否申请已经存在于数据库中
	 * @param contCode String
	 * @return boolean
	 * 
	 */
	public boolean isExist(String contCode){
		LoanAprv loanAprv = new LoanAprv();
		loanAprv = loanAprvDAO.findByContcode(contCode);
		if(null == loanAprv|| !(loanAprv instanceof LoanAprv) ){
			return false;
		}else{
			return true;
		}
		
	}
	
	/**
	 * 存储一条贷款审批记录到数据库
	 * @param loanApvr对象
	 * @return boolean
	 */
	public boolean saveToDB(LoanAprv loanAprv){
		boolean isSuc = true;
		try{
			loanAprvDAO.save(loanAprv);
		}catch(RuntimeException re){
			isSuc = false;
		}
		
		return isSuc;
	}
	
	/**
	 * 更新一条已经存在的记录
	 * @param loanAprv 对象
	 * @return boolean
	 */
	public boolean updateToDB(LoanAprv loanAprv){
		boolean isSuc = true;
		try{
			loanAprvDAO.attachDirty(loanAprv);
		} catch(RuntimeException re){
			isSuc = false;
		}
		
		return isSuc;
	}
	
	public static void main(String[] args){
		ApplicationContext ac = new ClassPathXmlApplicationContext("/spring/applicationContext.xml");
		LoanAprvService las = (LoanAprvService) SpringContextUtil.getBean("loanAprvService");
		
		boolean tmp = las.isExist("1234");
		//String test = "32323" ;
		///String test2 = null;
		//test = test.length() + test;
		//test = las.getLoanStat("1234");
		//System.out.println(test);
	}
}
